import tester
import sys
usage = "usage: checker --cmp <standard_module> <standard_module_path> <tested_module> <path_to_tested_module>\n"
usage+= "       checker --run <standard_module> <standard_module_path>"


def run(v, standard_module_path):
    sys.path.append(standard_module_path)
    
    executor = "import "+v+"\n"
    executor+= "print tester.dry_run("+v+".run_function)"
    exec(executor)

def check(v, standard_module_path, module, module_path):
    sys.path.append(module_path)
    sys.path.append(standard_module_path)
    
    executor = "import "+module+"\n"
    executor+= "import "+v+"\n"
    executor+= "print tester.test("+module+".main, "+v+".cmp_function)"
    exec(executor)
    
if __name__=="__main__":
    try:
        if sys.argv[1] == "--cmp":
            check(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
        elif sys.argv[1] == "--run":
            run(sys.argv[2], sys.argv[3])
    except IndexError:
        print sys.exc_info()
        print usage
        exit()
